home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / General / ProNET / src / drivers / internal-parallel.s next >
Text File  |  1996-11-30  |  10KB  |  524 lines

  1. *
  2. * internal-parallel (ProNET driver)
  3. *
  4.  
  5. ; Format of one packet is:
  6. ; 2bytes LENGTH of data including next two words in WORDS-1 !!!!!
  7. ; 2bytes Destination port
  8. ; 2bytes Source port
  9. ; xbytes DATA
  10.  
  11. DISABLEINTS    macro
  12.         move.w    #$4000,$dff09a
  13.         endm
  14. ENABLEINTS    macro
  15.         move.w    #$c000,$dff09a
  16.         endm
  17.  
  18.         include    "A:OSmacros.i"
  19.         include    "exec/exec.i"
  20.         include    "resources/misc.i"
  21.         include    "hardware/cia.i"
  22.         include    "P:include/devices/pronet.i"
  23.         include    "exec_lib.i"
  24.         include    "intuition_lib.i"
  25.         include    "dos_lib.i"
  26.  
  27. Init        movem.l    d2-d7/a2-a6,-(sp)
  28.         move.l    a0,a4
  29.         move.l    a1,a5
  30.         cmp.l    #"RST!",d0        ;compare ID
  31.         bne    .ende
  32.         cmp.l    #2,d1
  33.         bne.s    .ende
  34.  
  35.         move.l    #PNDRVERR_WRONG_ARGS,RC
  36.         move.l    a5,a0
  37.         bsr    dec2slong
  38.         tst.w    d4
  39.         bmi.s    .ende
  40.         move.w    d1,MACHINE
  41.         bsr    dec2slong
  42.         tst.w    d4
  43.         bmi.s    .ende
  44.         move.w    d1,PRIORITY
  45.  
  46.         bsr    TrapOpenDevice
  47.  
  48.         bsr    AllocPPort
  49.         tst.w    d0
  50.         bne.s    .ende
  51.  
  52.         bsr    InitTransfer
  53.  
  54.         move.l    4.w,a6
  55.         move.l    ThisTask(a6),a1
  56.         move.w    PRIORITY(pc),d0
  57.         LIBCALL    SetTaskPri
  58.  
  59.         move.b    INTsigbit(pc),pndd_ReadSignalBit(a4)
  60.         move.l    #ReadQuery,pndd_ReadQuery(a4)
  61.         move.l    #ReadFlush,pndd_ReadFlush(a4)
  62.         move.l    #Read,pndd_Read(a4)
  63.         move.l    #Write,pndd_Write(a4)
  64.         move.l    #Exit,pndd_Exit(a4)
  65.  
  66.         clr.l    RC
  67.  
  68. .ende        movem.l    (sp)+,d2-d7/a2-a6
  69.         move.l    RC(pc),d0
  70.         rts
  71.  
  72. RC        dc.l    0
  73.  
  74.         dc.b    "$VER: internal-parallel 37.0 (30.11.96)",13,10,0
  75.         even
  76.  
  77. Exit        movem.l    d2-d7/a2-a6,-(sp)
  78.         bsr    ExitTransfer
  79.         bsr    FreePPort
  80.         bsr    UnTrapOpenDevice
  81.         movem.l    (sp)+,d2-d7/a2-a6
  82.         rts
  83.  
  84. PRIORITY    dc.w    0
  85. MACHINE        dc.w    0
  86.  
  87. dec2slong    ; konvertiert Dezimalstring ab (a0) zu Longword in D1 !!
  88.         ; SIGNED!
  89.         moveq    #-1,d4
  90.         moveq    #0,d1
  91.         moveq    #0,d3
  92.         move.b    (a0),d0
  93.         cmp.b    #"-",d0
  94.         bne.s    .loop
  95.         addq.l    #1,a0
  96.         st    d3
  97. .loop        moveq    #0,d0
  98.         move.b    (a0)+,d0
  99.         sub.b    #"0",d0
  100.         cmp.b    #9,d0
  101.         bhi.s    .oki
  102.         clr.l    d4
  103.         move.l    d1,d2
  104.         lsl.l    #3,d1
  105.         add.l    d2,d1
  106.         add.l    d2,d1
  107.         add.l    d0,d1
  108.         bra.s    .loop
  109. .oki        tst.w    d3
  110.         beq.s    .ende
  111.         neg.l    d1
  112. .ende        rts
  113.  
  114. ReadQuery    movem.l    d3-d7/a2-a6,-(sp)
  115.         lea    $bfd000,a2    ; test if packet is pending
  116.         btst    #0,(a2)
  117.         bne.s    .error
  118.         lea    $bfd200,a3    ; ciab ddra
  119.         bset    #1,(a3)        ; set POUT (ack) line to output
  120.         lea    buffer-2(pc),a4    ; first word is `empty'
  121.         moveq    #3,d4        ; (due to handshake init)
  122.         bsr    ReceiveData
  123.         movem.w    buffer(pc),d0-d2
  124.         subq.w    #2-1,d0
  125.         add.w    d0,d0
  126.         movem.l    (sp)+,d3-d7/a2-a6
  127.         rts
  128. .error        moveq    #0,d0
  129.         movem.l    (sp)+,d3-d7/a2-a6
  130.         rts
  131.  
  132. ReadFlush
  133.         movem.l    d2-d7/a2-a6,-(sp)
  134.         move.w    buffer(pc),d4
  135.         subq.w    #2,d4
  136.         bsr    FlushData
  137.         bra.s    read_entry
  138.  
  139. Read
  140.         movem.l    d2-d7/a2-a6,-(sp)
  141.         move.l    a0,a4
  142.         move.w    buffer(pc),d4
  143.         subq.w    #2,d4
  144.         bsr    ReceiveData
  145. read_entry    lea    $bfd200,a3    ; ciab ddra
  146.         bclr    #1,(a3)        ; set POUT(ack) line to input
  147.         movem.l    (sp)+,d2-d7/a2-a6
  148.         rts
  149.  
  150. Write        movem.l    d2-d7/a2-a6,-(sp)
  151.  
  152.         lea    buffer(pc),a5
  153.         move.l    a0,6(a5)
  154.         move.l    d0,10(a5)
  155.  
  156.         move.w    d1,(a5)
  157.         move.w    d2,2(a5)
  158.  
  159.         move.w    d0,d4
  160.         lsr.w    #1,d4
  161.         addq.w    #2-1,d4
  162.         bsr    AcquireLine
  163.         tst.w    d0            ;Line is busy now! Try later
  164.         bne.s    .ende
  165.  
  166.         move.l    a5,a4
  167.         moveq    #1,d4
  168.         moveq    #0,d6
  169.         bsr    SendData
  170.  
  171.         move.l    6(a5),a4    ; The last word gets sent separately.
  172.         move.l    10(a5),d4
  173.         lsr.w    #1,d4
  174.         subq.w    #2,d4
  175.         bmi.s    .0
  176.         bsr    SendData
  177.  
  178. .0        DISABLEINTS        * We don't take too long here
  179.         moveq    #0,d4        * in case the other machine wants
  180.         bsr    SendData    * to send something...
  181.  
  182.         lea    $bfd200,a3
  183.         and.b    #%11111000,(a3)    ; all control lines input
  184.         lea    $bfe301,a1
  185.         sf    (a1)        ; data lines input, too
  186.         lea    $bfd000,a2    ; ciab pra   ==> CONTROL LINES
  187.         or.b    #%00000111,(a2)
  188.         ENABLEINTS
  189.  
  190.         moveq    #0,d0
  191. .ende        movem.l    (sp)+,d2-d7/a2-a6
  192.         rts
  193.  
  194.         dc.w    0
  195. buffer        dc.w    0,0,0
  196.         dc.l    0,0
  197.  
  198. ** -----------------------------------------------------------------------
  199. **
  200. **
  201. **
  202. **
  203.  
  204. **
  205. ** Parallel.device trapping
  206. **
  207.  
  208. **
  209. **
  210. **
  211. **
  212. ** -----------------------------------------------------------------------
  213.  
  214. TrapOpenDevice    move.l    4.w,a6
  215.         move.l    a6,a1
  216.         move.l    #_LVOOpenDevice,a0
  217.         move.l    #.trap,d0
  218.         LIBCALL    SetFunction
  219.         move.l    d0,orgopendev
  220.         rts
  221. .trap        movem.l    a0/a1/d0/d1,-(sp)
  222.         lea    parname(pc),a1
  223.         bsr    CompareStrings
  224.         tst.w    d0
  225.         bne.s    .openit
  226.         movem.l    (sp)+,a0/a1/d0/d1
  227.         move.b    #-1,IO_ERROR(a1)
  228.         moveq    #-1,d0            ;IOERR_OPENFAIL
  229.         rts
  230. .openit        movem.l    (sp)+,a0/a1/d0/d1
  231.         move.l    a2,-(sp)
  232.         move.l    orgopendev(pc),a2
  233.         jsr    (a2)
  234.         move.l    (sp)+,a2
  235.         rts
  236. orgopendev    dc.l    0
  237.  
  238. UnTrapOpenDevice
  239.         move.l    4.w,a6
  240.         move.l    a6,a1
  241.         move.l    #_LVOOpenDevice,a0
  242.         move.l    orgopendev(pc),d0
  243.         LIBCALL    SetFunction
  244.         rts
  245.  
  246. ; -- Compare two null-terminated strings. Case-insensitive
  247. CompareStrings    ; a0 *String1
  248.         ; a1 *String2
  249.         ; RETURNS d0 = 0 --> Strings equal
  250.         move.l    d2,-(sp)
  251.         moveq    #-1,d0
  252. .loop        move.b    (a0)+,d1
  253.         move.b    (a1)+,d2
  254.         bclr    #5,d1
  255.         bclr    #5,d2
  256.         cmp.b    d1,d2
  257.         bne.s    .ende
  258.         tst.b    d1
  259.         bne.s    .loop
  260.         moveq    #0,d0
  261. .ende        move.l    (sp)+,d2
  262.         rts
  263.  
  264. parname        dc.b    "parallel.device",0
  265.  
  266. ** -----------------------------------------------------------------------
  267. **
  268. **
  269. **
  270. **
  271.  
  272. **
  273. ** Built-in Parallel Port Transfer routines
  274. **
  275.  
  276. **
  277. **
  278. **
  279. **
  280. ** -----------------------------------------------------------------------
  281.  
  282. ; -- Allocate Parallel Port Registers
  283. AllocPPort    lea    miscname(pc),a1
  284.         move.l    4.w,a6
  285.         LIBCALL    OpenResource
  286.         move.l    #err1,RC
  287.         move.l    d0,miscbase
  288.         beq.s    APP_nores
  289.  
  290.         move.l    d0,a6
  291.         move.l    #MR_PARALLELPORT,d0
  292.         lea    INTname(pc),a1
  293.         jsr    -6(a6)            ;AllocMiscResource
  294.         move.l    #err2,RC
  295.         tst.w    d0
  296.         bne.s    APP_noport
  297.  
  298.         move.l    #MR_PARALLELBITS,d0
  299.         lea    INTname(pc),a1
  300.         jsr    -6(a6)
  301.         move.l    #err3,RC
  302.         tst.w    d0
  303.         bne.s    APP_nobits
  304.  
  305.         moveq    #0,d0
  306.         rts
  307.  
  308. FreePPort    move.l    miscbase(pc),a6
  309.         move.l    #MR_PARALLELBITS,d0
  310.         jsr    -12(a6)
  311. APP_nobits    move.l    #MR_PARALLELPORT,d0
  312.         jsr    -12(a6)
  313. APP_noport
  314. APP_nores    moveq    #-1,d0
  315.         rts
  316.  
  317. miscname    dc.b    "misc.resource",0
  318. ciaaname    dc.b    "ciaa.resource",0
  319. err1        dc.b    "Can't find misc.resource.",0
  320. err2        dc.b    "Can't allocate misc/MR_PARALLELPORT.",0
  321. err3        dc.b    "Can't allocate misc/MR_PARALLELBITS.",0
  322.         even
  323. miscbase    dc.l    0
  324. ciaabase    dc.l    0
  325.  
  326. ; -- Init Transfer routines
  327. InitTransfer    move.l    4.w,a6
  328.         move.l    ThisTask(a6),INTsigtask
  329.  
  330.         moveq    #-1,d0
  331.         LIBCALL    AllocSignal
  332.         move.b    d0,INTsigbit
  333.  
  334.         bsr    InitParallel
  335.  
  336.         lea    ciaaname(pc),a1
  337.         move.l    4.w,a6
  338.         LIBCALL    OpenResource
  339.         move.l    d0,a6
  340.         move.l    d0,ciaabase
  341.         moveq    #CIAICRB_FLG,d0
  342.         lea    INTstruct(pc),a1
  343.         jsr    -6(a6)
  344.  
  345.         rts
  346.  
  347. ExitTransfer    move.l    ciaabase(pc),a6
  348.         moveq    #CIAICRB_FLG,d0
  349.         lea    INTstruct(pc),a1
  350.         jsr    -12(a6)
  351.         move.l    4.w,a6
  352.         move.b    INTsigbit(pc),d0
  353.         LIBCALL    FreeSignal
  354.         rts
  355.  
  356. INTsigtask    dc.l    0
  357. INTsigbit    dc.w    0
  358.  
  359. INTstruct    dc.l    0,0
  360.         dc.b    2,127
  361.         dc.l    INTname
  362.         dc.l    0,INTcode
  363. INTname        dc.b    "ProNET Internal-Parallel Driver",0
  364.         even
  365. INTcode        lea    $bfd000,a0        ;check if the interrupt
  366.         btst    #0,(a0)            ;was `correct' or caused
  367.         bne.s    .no            ;by switching on the remote
  368.         move.l    4.w,a6            ;machine
  369.         move.l    INTsigtask(pc),a1
  370.         move.b    INTsigbit(pc),d1
  371.         moveq    #0,d0
  372.         bset    d1,d0
  373.         LIBCALL    Signal
  374. .no        moveq    #1,d0
  375.         rts
  376.  
  377. ;:---------------------------------------------------------------------------
  378. ;:-- InitParallel
  379. InitParallel
  380.         lea    $bfe101,a0    ; ciaa prb   ==> DATA LINES
  381.         lea    $bfe301,a1    ; ciaa ddrb
  382.         lea    $bfd000,a2    ; ciab pra   ==> CONTROL LINES
  383.         lea    $bfd200,a3    ; ciab ddra
  384.  
  385.         and.b    #%11111000,(a3)    ; all control lines input  ---|
  386.         sf    (a1)        ; [[data lines input, too]]   v
  387.         or.b    #%00000111,(a2)    ; and 1 when we set them to output
  388.         rts
  389.  
  390. ;:---------------------------------------------------------------------------
  391. ;:-- AcquireLine
  392. ;:-- d4 Number of words-1 that will be sent !
  393. ;:-- !!!!!! RETURNS d0=0  if no error
  394. ;:--                d0=-1 if line was busy
  395. AcquireLine
  396.         lea    $bfd000,a2    ; ciab pra   ==> CONTROL LINES
  397.         lea    $bfd200,a3    ; ciab ddra
  398.  
  399.         DISABLEINTS
  400.         btst    #0,(a2)
  401.         bne.s    .free
  402.         ENABLEINTS
  403.         moveq    #-1,d0
  404.         rts
  405.  
  406. .free        bset    #0,(a3)
  407.         bclr    #0,(a2)
  408.  
  409.         bset    #2,(a3)        ; cause interrupt by quickly toggling
  410.         bclr    #2,(a2)        ; the FLAG input of the other
  411.         bset    #2,(a2)        ; machine
  412.         bclr    #2,(a3)
  413.  
  414.         move.l    ciaabase(pc),a6    ; reset interrupt flag which was
  415.         moveq    #CIAICRF_FLG,d0    ; set on our machine, too
  416.         jsr    -24(a6)        ; (SEL&ACK connected at parallel port)
  417.  
  418.         ENABLEINTS
  419.  
  420.         lea    $bfe101,a0    ; ciaa prb   ==> DATA LINES
  421.         lea    $bfe301,a1    ; ciaa ddrb
  422.  
  423.         tst.w    firstpacketflag    ; no timeout for the first packet!
  424.         beq.s    .acknotimeout
  425.         tst.w    MACHINE        ; no timeout for machine 1!
  426.         bne.s    .acknotimeout
  427.  
  428.         move.l    #100000,d0
  429. .ack0        btst    #1,(a2)        ; wait for it to respond...
  430.         beq.s    .ack0ok
  431.         subq.l    #1,d0
  432.         bne.s    .ack0
  433.  
  434.         bset    #0,(a2)
  435.         and.b    #%11111000,(a3)    ; TIMEOUT! reset all lines
  436.         or.b    #%00000111,(a2)
  437.         bsr    INTcode
  438.         moveq    #-1,d0
  439.         rts
  440.  
  441. .acknotimeout    btst    #1,(a2)
  442.         bne.s    .acknotimeout
  443.  
  444. .ack0ok        st    firstpacketflag
  445.         bset    #0,(a2)        ; and initialize handshake sequence
  446. .ack1        btst    #1,(a2)
  447.         beq.s    .ack1
  448.  
  449.         st    (a1)        ; set data lines to output now
  450.         ror.w    #8,d4        ; and hand the length word over
  451.         move.b    d4,(a0)        ; to the remote machine
  452.         bclr    #0,(a2)
  453.         ror.w    #8,d4
  454. .ack2        btst    #1,(a2)
  455.         bne.s    .ack2
  456.         move.b    d4,(a0)
  457.         bset    #0,(a2)
  458. .ack3        btst    #1,(a2)
  459.         beq.s    .ack3
  460.         moveq    #0,d0
  461.         rts
  462.  
  463. firstpacketflag    dc.w    0
  464.  
  465. ;:---------------------------------------------------------------------------
  466. ;:-- SendData
  467. ;:-- a4 *data
  468. ;:-- d4 datalength in words-1
  469. SendData
  470.         lea    $bfe101,a0    ; ciaa prb   ==> DATA LINES
  471.         lea    $bfd000,a2    ; ciab pra   ==> CONTROL LINES
  472.  
  473.         move.b    #%11111110,d0
  474.         move.b    #%00000001,d1
  475.  
  476. .loop        move.b    (a4)+,(a0)    ; fully handshaked data txfer
  477.         and.b    d0,(a2)
  478. .ack0        btst    #1,(a2)
  479.         bne.s    .ack0
  480.         move.b    (a4)+,(a0)
  481.         or.b    d1,(a2)
  482. .ack1        btst    #1,(a2)
  483.         beq.s    .ack1
  484.         dbra    d4,.loop
  485.         rts
  486.  
  487. ;:---------------------------------------------------------------------------
  488. ;:-- ReceiveData
  489. ;:-- a4 *datadest
  490. ;:-- d4 datalength in words-1
  491. ReceiveData
  492.         lea    $bfe101,a0    ; ciaa prb   ==> DATA LINES
  493.         lea    $bfd000,a2    ; ciab pra   ==> CONTROL LINES
  494.  
  495.         move.b    #%11111101,d0
  496.         move.b    #%00000010,d1
  497.  
  498. .loop        btst    #0,(a2)
  499.         bne.s    .loop
  500.         move.b    (a0),(a4)+
  501.         and.b    d0,(a2)
  502. .ack0        btst    #0,(a2)
  503.         beq.s    .ack0
  504.         move.b    (a0),(a4)+
  505.         or.b    d1,(a2)
  506.         dbra    d4,.loop
  507.         rts
  508.  
  509. FlushData
  510.         lea    $bfe101,a0    ; ciaa prb   ==> DATA LINES
  511.         lea    $bfd000,a2    ; ciab pra   ==> CONTROL LINES
  512.  
  513.         move.b    #%11111101,d0
  514.         move.b    #%00000010,d1
  515.  
  516. .loop        btst    #0,(a2)
  517.         bne.s    .loop
  518.         and.b    d0,(a2)
  519. .ack0        btst    #0,(a2)
  520.         beq.s    .ack0
  521.         or.b    d1,(a2)
  522.         dbra    d4,.loop
  523.         rts
  524.